package com.jeethink.web.controller.gs;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.gs.domain.GsTaskReportForm;
import com.jeethink.gs.service.GsTaskReportFormService;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 任务报Controller
 * 
 * @author jeethink
 * @date 2022-08-10
 */
@Controller
@RequestMapping("/gs/form")
public class GsTaskReportFormController extends BaseController
{
    private String prefix = "gs/form";

    @Autowired
    private GsTaskReportFormService gsTaskReportFormService;

    @RequiresPermissions("system:form:view")
    @GetMapping()
    public String form()
    {
        return prefix + "/form";
    }

    /**
     * 查询任务报列表
     */
    @RequiresPermissions("system:form:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GsTaskReportForm gsTaskReportForm)
    {
        startPage();
        List<GsTaskReportForm> list = gsTaskReportFormService.selectGsTaskReportFormList(gsTaskReportForm);
        return getDataTable(list);
    }

    /**
     * 导出任务报列表
     */
    @RequiresPermissions("system:form:export")
    @Log(title = "任务报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GsTaskReportForm gsTaskReportForm)
    {
        List<GsTaskReportForm> list = gsTaskReportFormService.selectGsTaskReportFormList(gsTaskReportForm);
        ExcelUtil<GsTaskReportForm> util = new ExcelUtil<GsTaskReportForm>(GsTaskReportForm.class);
        return util.exportExcel(list, "form");
    }

    /**
     * 新增任务报
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存任务报
     */
    @RequiresPermissions("system:form:add")
    @Log(title = "任务报", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GsTaskReportForm gsTaskReportForm)
    {
        return toAjax(gsTaskReportFormService.insertGsTaskReportForm(gsTaskReportForm));
    }

    /**
     * 修改任务报
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GsTaskReportForm gsTaskReportForm = gsTaskReportFormService.selectGsTaskReportFormById(id);
        mmap.put("gsTaskReportForm", gsTaskReportForm);
        return prefix + "/edit";
    }

    /**
     * 修改保存任务报
     */
    @RequiresPermissions("system:form:edit")
    @Log(title = "任务报", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GsTaskReportForm gsTaskReportForm)
    {
        return toAjax(gsTaskReportFormService.updateGsTaskReportForm(gsTaskReportForm));
    }

    /**
     * 删除任务报
     */
    @RequiresPermissions("system:form:remove")
    @Log(title = "任务报", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gsTaskReportFormService.deleteGsTaskReportFormByIds(ids));
    }


    @PostMapping( "/selReportFormByUser")
    @ResponseBody
    public TableDataInfo selReportFormByUser(@RequestParam(value = "name",defaultValue = "") String name){
        startOrderBy();
        return getDataTable(gsTaskReportFormService.selReportFormByUser(name));
    }
}
